/**
 *Syslib movementation effects class
 * @version 0.1
 */
syslib.ui.fx.Move = {
	move : function(element, coords){
		// set the element as absolute
		element.style.left = coords.x + "px"
		element.style.top = coords.y + "px"
	}, 
	
	getCenterPoint : function(element){
		// get the element dimensions
		var dimensions = syslib.element.getDimensions(element);
	
		// calcule the center
		var leftMiddle = document.body.scrollLeft + ( document.body.clientWidth / 2);
		var topMiddle = document.body.scrollTop + ( document.body.clientHeight / 2);
		
		return {
			x : leftMiddle - (dimensions.width / 2), 
			y : topMiddle - (dimensions.height / 2)
		};
	}, 
	
	toPoint : function(element, x, y, lastX, lastY){
		// get the element's current position
		var position = syslib.ui.position.getAbsolutePosition(element);
		
		// calcule the space to move
		var distanceX = (x - position.x) / 8;
		var newX = position.x + distanceX;
		var distanceY = (y - position.y) / 8;
		var newY = position.y + distanceY;
		
		if(newX == lastX && newY == lastY){
			// move the element to the final position
			this.move(element, {
				x: x, 
				y: y
			});
		} else {
			// move the element
			this.move(element,  {
				x : newX, 
				y : newY
			});
			
			// set the interval
			setTimeout(function(){
				syslib.ui.fx.Move.toPoint(element, x, y, newX, newY);
			}, 20);
		}
	}, 
	toCenter : function(element){
		// get the center point
		var center = this.getCenterPoint(element);
		
		
		this.toPoint(element, center.x, center.y);
	}
};